<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org" xmlns:shiro="http://www.pollix.at/thymeleaf/shiro">
<head>
	<th:block th:include="common/include :: header('服务单项')" />
</head>
<body class="gray-bg">
<div class="container-div">
	<div class="row">
		<div class="col-sm-12 search-collapse">
			<form id="post-form">
				<div class="select-list">
					<ul>
						<li>
							名称：<input type="text" name="name"/>
						</li>
						<li>
							是否套餐：
							<select name="carPackage" th:with="type=${@dict.getType('si_car_package')}">
								<option value="">所有</option>
								<option th:each="dict : ${type}" th:text="${dict.label}" th:value="${dict.value}"></option>
							</select>
						</li>
						<li>
							服务类型：
							<select name="serviceCatalog" th:with="type=${@dict.getType('si_service_catalog')}">
								<option value="">所有</option>
								<option th:each="dict : ${type}" th:text="${dict.label}" th:value="${dict.value}"></option>
							</select>
						</li>
						<li>
							审核类型：
							<select name="auditStatus" th:with="type=${@dict.getType('si_audit_status')}">
								<option value="">所有</option>
								<option th:each="dict : ${type}" th:text="${dict.label}" th:value="${dict.value}"></option>
							</select>
						</li>
						<li>
							上架状态：
							<select name="saleStatus" th:with="type=${@dict.getType('si_sale_status')}">
								<option value="">所有</option>
								<option th:each="dict : ${type}" th:text="${dict.label}" th:value="${dict.value}"></option>
							</select>
						</li>
						<li>
							<a class="btn btn-primary btn-rounded btn-sm" onclick="$.table.search()"><i class="fa fa-search"></i>&nbsp;搜索</a>
							<a class="btn btn-warning btn-rounded btn-sm" onclick="$.form.reset()"><i class="fa fa-refresh"></i>&nbsp;重置</a>
						</li>
					</ul>
				</div>
			</form>
		</div>

		<div class="btn-group-sm" id="toolbar" role="group">
			<a class="btn btn-success" onclick="$.operate.add()" shiro:hasPermission="system:serviceItem:add">
				<i class="fa fa-plus"></i> 新增
			</a>
			<a class="btn btn-danger" onclick="$.operate.removeAll()" shiro:hasPermission="system:serviceItem:add">
				<i class="fa fa-plus"></i> 删除
			</a>
			<a class="btn btn-success disabled" id="startAudit" onclick="startAudit()">
				<i class="fa fa-plus"></i> 发起审核
			</a>

		</div>

		<div class="col-sm-12 select-table table-striped">
			<table id="bootstrap-table"></table>
		</div>
	</div>
</div>
<th:block th:include="common/include :: footer" />
<script th:inline="javascript">
	var editFlag = [[${@permission.hasPermi('system:serviceItem:edit')}]];
	var removeFlag = [[${@permission.hasPermi('system:serviceItem:remove')}]];
	var carPackageDatas = [[${@dict.getType('si_car_package')}]];
	var serviceCatalogDatas = [[${@dict.getType('si_service_catalog')}]];
	var auditStatusDatas = [[${@dict.getType('si_audit_status')}]];
	var saleStatusDatas = [[${@dict.getType('si_sale_status')}]];
	var prefix = ctx + "/business/serviceItem";
	$(function() {
		var options = {
			url: prefix + "/query",  			 		//查询的url
			createUrl: prefix + "/addPage",  			//跳转到新增页面的地址
			updateUrl: prefix + "/editPage?id={id}",  	//跳转到编辑界面的地址
			removeUrl: prefix + "/remove",				//删除的地址
			exportUrl: prefix + "/export",				//做表格导出的地址
			modalName: "服务单项",							//模态框的名称
			columns: [{
				checkbox: true
			},
				{
					field: 'id',
					title: '服务id',
					visible: false//是否隐藏id
				},
				{
					field: 'name',
					title: '服务项名称',
					sortable: true
				},
				{
					field: 'originalPrice',
					title: '服务项原价',
					sortable: true
				},
				{
					field: 'discountPrice',
					title: '服务项折扣价',
					sortable: true
				},
				{
					field: 'carPackage',
					title: '是否套餐',
					sortable: true,
					formatter: function(value, row, index) {
						return $.table.selectDictLabel(carPackageDatas, value);
					}

				},
				{
					field: 'info',
					title: '备注信息',
					sortable: true,
					//备注只显示5个字，其他内容省略
					formatter: function(value, row, index) {
						return $.table.tooltip(value, 5, "open");
					}
				},
				{
					field: 'serviceCatalog',
					title: '服务分类',
					sortable: true,
					formatter: function(value, row, index) {
						return $.table.selectDictLabel(serviceCatalogDatas, value);
					}
				},
				{
					field: 'auditStatus',
					title: '审核状态',
					sortable: true,
					formatter: function(value, row, index) {
						return $.table.selectDictLabel(auditStatusDatas, value);
					}
				},
				{
					field: 'saleStatus',
					title: '上架状态',
					sortable: true,
					formatter: function(value, row, index) {
						return $.table.selectDictLabel(saleStatusDatas, value);
					}
				},
				{
					title: '操作',
					align: 'center',
					formatter: function(value, row, index) {
						var actions = [];
						var editClass='';
						//当项目处于上架状态或者审核中的项目不能被编辑
						if(row.saleStatus ==1 || row.auditStatus == 1){
							editClass='disabled';
						}
						actions.push('<a class="btn btn-success btn-xs '+editClass+' " href="javascript:void(0)" ' +
								'onclick="$.operate.edit(\'' + row.id + '\')"><i class="fa fa-edit"></i>编辑</a> ');
						if(row.saleStatus==1){//上架，显示下架
							actions.push('<a class="btn btn-info btn-xs " href="javascript:void(0)" ' +
									'onclick="saleOff(\'' + row.id + '\')"><i class="fa fa-edit"></i>下架</a> ');
						}else{
							//上架：套餐类的在审核中的项目不能上架，非套餐类的能直接上架  只能处于下架状态的项目才能上架
							//不能上架，把按钮显示成灰
							var onSaleClass='';
							if(row.carPackage &&  row.auditStatus!=2) {
								onSaleClass='disabled';
							}
							actions.push('<a class="btn btn-danger btn-xs '+onSaleClass+' " href="javascript:void(0)"' +
									' onclick="saleOn(\'' + row.id + '\')"><i class="fa fa-remove"></i>上架</a>');
						}

						return actions.join('');
					}
				}]
		};
		$.table.init(options);
	});


	function saleOn(id) {
		$.modal.confirm("确定要上架吗？", function() {
			$.operate.get("/business/serviceItem/saleOn?id="+id);
		});
	}
	function saleOff(id) {
		$.modal.confirm("确定要上架吗？", function() {
			$.operate.get("/business/serviceItem/saleOff?id="+id);
		});
	}

	//发起审核的逻辑判断
	//当选中一个，取消一个，选中全部，不选中全部
	$('#bootstrap-table').on('check.bs.table uncheck.bs.table check-all.bs.table uncheck-all.bs.table', function () {
		//获取选中的数据
		var rows = $('#bootstrap-table').bootstrapTable('getSelections');
		//判断选中数据的个数，若是个数大于1 或者 等于0让按钮变灰
		if (rows.length > 1 || rows.length == 0) {
			$('#startAudit').addClass("disabled");
			return;
		}
		//判断数据的套餐情况,若是非套餐，让按钮变灰
		var row = rows[0];
		if (row.carPackage == 0) {
			$('#startAudit').addClass("disabled");
			return;
		}
		//判断数据的审核状态，若审核状态为审核中或者审核通过的状态那么让按钮变灰
		if (row.auditStatus == 1 || row.auditStatus == 2) {
			$('#startAudit').addClass("disabled");
			return;
		}
		//去除disabled
		$('#startAudit').removeClass("disabled");
	});

	//点击发起审核按钮，传入id
	function startAudit() {
		//获取id
		var rows = $('#bootstrap-table').bootstrapTable('getSelections');
		var row = rows[0];
		$.modal.open("审核详情","/business/serviceItem/auditPage?id="+row.id);
	}
</script>
</body>
</html>